$(function(){
	//打分,判断后台传过来的值
var score1=parseFloat($('.score1').eq(0).html())
var score2=parseFloat($('.score2').eq(0).html())
var score3=parseFloat($('.score3').eq(0).html())
var score = parseFloat((score1+score2+score3)/3).toFixed(1) + '分'
//console.log(score);
$('.total-score').eq(0).html(score);
	//判断进度条的长度
	var w = $('.store-average-score span').eq(0).width();
	$('.store-progress').width(parseFloat(score)/5*w);
	
	//商品小轮播图
		//鼠标移入事件
		//声明3个数组分别存储下方的四个小图和其对应的四个大图,以及最大图
		var small = ["../img/sjia/small.png","../img/sjia/small.png","../img/sjia/small.png","../img/sjia/small.png"];
		var  big =  ["../img/sjia/big.png","../img/photo/1.jpg","../img/sjia/big.png","../img/sjia/big.png"];
		var xbig = ["../img/sjia/xbig.png","../img/photo/1.jpg","../img/sjia/xbig.png","../img/sjia/xbig.png"];
		var storeIndex = 0;
	$('.store-lb-small img').each(function(i,e){
		storeIndex=i-1;
		$(e).click(function(){
			$(this).siblings().removeClass('active');
			$(this).addClass('active');
			//换中等大图
			$(bigImg).eq(0).attr('src',$(this).attr('src'));
			var str =  $(bigImg).eq(0).attr('src');
			//换放大镜大图
			$('.store-scale-img').attr('src',str );
		})
	})
		//左右按钮点击效果:声明一个变量存储当前的图片下标
			$('.store-lb-left').click(function(){
						$('.store-lb-right').css('opacity',1);
				if(storeIndex<=0){
					storeIndex=0;
					$(this).css('opacity',0.2);
				}else{
					storeIndex --;
					$(this).css('opacity',1);
				}
				$('.store-lb-small img').eq(storeIndex).siblings().removeClass('active');
				$('.store-lb-small img').eq(storeIndex).addClass('active');
			})
		$('.store-lb-right').click(function(){
						$('.store-lb-left').css('opacity',1);
				if(storeIndex>=3){
					storeIndex=3;
					$(this).css('opacity',0.1);
				}else{
					storeIndex ++;
					$(this).css('opacity',1);
				}
				$('.store-lb-small img').eq(storeIndex).siblings().removeClass('active');
				$('.store-lb-small img').eq(storeIndex).addClass('active');
		})
		
		
		//放大镜效果


			var small = document.querySelector('.smallDiv');
			var big = document.querySelector('.store-scale');
			var zoom = document.querySelector('.store-room');
			var bigImg = document.querySelector('.store-scale-img');
			small.onmousemove = function(e) {
				var even = e || event;
				var x = even.clientX - zoom.offsetWidth / 2 -  $(small).offset().left;
				var y = even.clientY - zoom.offsetHeight / 2 - $(small).offset().top;
				var maxX = small.clientWidth - zoom.clientWidth;
				var maxY = small.clientHeight - zoom.clientHeight;
				//以下四个 i f判断 黄色遮罩 可移动区域
				if(x <= 0) {
					x = 0;
				}
				if(x >=  maxX) {
					x =  maxX;
				}
				if(y < 0) {
					y = 0;
				}
				if(y >= maxY) {
					y = maxY;
				}
				zoom.style.left = x + 'px';
				zoom.style.top = y + 'px';
				
				var bigImgX = ( x / maxX ) * ( bigImg.offsetWidth - big.clientWidth );
				var bigImgY = ( y / maxY ) * ( bigImg.clientHeight - big.clientHeight);
				
				//给 big 区域添加滚动
				big.scrollLeft = bigImgX;
				big.scrollTop = bigImgY;
			}
			
			//给 small 添加鼠标移入移出事件
			small.onmouseenter = function(){
				zoom.style.display = 'block';
				big.style.display = 'block';
			}
			small.onmouseleave= function(){
				zoom.style.display = 'none';
				big.style.display = 'none';
			}
})